#include "myslider.h"
#include"player.h"
mySlider::mySlider(QWidget* p){
    setParent(p);
    setOrientation(Qt::Horizontal);
    setGeometry(800,639,350,31);
    setStyleSheet("QSlider{border-image: url(:/pic/pic/back2.jpg);}QSlider::groove:horizontal {border: 0px solid #bbb;}QSlider::sub-page:horizontal {background: rgb(232, 232, 232);border-radius: 2px;margin-top:8px;margin-bottom:8px;}QSlider::add-page:horizontal {background: rgb(158, 158, 158);border: 0px solid #777;border-radius: 2px;margin-top:9px;margin-bottom:9px;}QSlider::handle:horizontal {background: rgb(193,204,208);width: 5px;border: 1px solid rgb(193,204,208);border-radius: 2px; margin-top:6px;margin-bottom:6px;}QSlider::handle:horizontal:hover {background: rgb(193,204,208);width: 10px;border: 1px solid rgb(193,204,208);border-radius: 5px; margin-top:4px;margin-bottom:4px;}");
    connect(this,SIGNAL(valueChanged(int)),p,SLOT(progressChange()));//必须在这里connect，在下面函数里会异常结束

}

void mySlider::mousePressEvent(QMouseEvent *ev){
    //获取当前点击位置,得到的这个鼠标坐标是相对于当前QSlider的坐标
    int currentX = ev->pos().x();
    //获取当前点击的位置占整个Slider的百分比
    double per = currentX *1.0 /this->width();
    //利用算得的百分比得到具体数字
    int value = per*(this->maximum() - this->minimum()) + this->minimum();
    //设定滑动条位置
    this->setValue(value);
    QSlider::mousePressEvent(ev);
}
